package com.example.curd.demo.controller;

import com.example.curd.demo.domain.User;
import com.example.curd.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    //@RequestMapping("/user")
    public String getAllUser() {
        List<User> allUser = userService.getAllUsers();

        for (User user : allUser) {
            System.out.println(user);
        }

        return "查询查询查询";
    }

    @GetMapping(value = "/user", produces = {"application/json;charset=UTF-8"})
    public String getAllUser(Model model) {
        List<User> allUser = userService.getAllUsers();
        model.addAttribute("users", allUser);
        return "index";
    }
}
